package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.Repair;
import com.ruoyi.community.service.IRepairService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报修信息Controller
 * 
 * @author Sea
 * @date 2025-01-02
 */
@DataSource(DataSourceType.SLAVE)
@RestController
@RequestMapping("/community/repair")
public class RepairController extends BaseController
{
    @Autowired
    private IRepairService repairService;

    /**
     * 查询报修信息列表
     */
    @PreAuthorize("@ss.hasPermi('community:repair:list')")
    @GetMapping("/list")
    public TableDataInfo list(Repair repair)
    {
        startPage();
        List<Repair> list = repairService.selectRepairList(repair);
        return getDataTable(list);
    }

    /**
     * 导出报修信息列表
     */
    @PreAuthorize("@ss.hasPermi('community:repair:export')")
    @Log(title = "报修信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Repair repair)
    {
        List<Repair> list = repairService.selectRepairList(repair);
        ExcelUtil<Repair> util = new ExcelUtil<Repair>(Repair.class);
        util.exportExcel(response, list, "报修信息数据");
    }

    /**
     * 获取报修信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:repair:query')")
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId)
    {
        return success(repairService.selectRepairByRepairId(repairId));
    }

    /**
     * 新增报修信息
     */
    @PreAuthorize("@ss.hasPermi('community:repair:add')")
    @Log(title = "报修信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Repair repair)
    {
        return toAjax(repairService.insertRepair(repair));
    }

    /**
     * 修改报修信息
     */
    @PreAuthorize("@ss.hasPermi('community:repair:edit')")
    @Log(title = "报修信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Repair repair)
    {
        return toAjax(repairService.updateRepair(repair));
    }

    /**
     * 删除报修信息
     */
    @PreAuthorize("@ss.hasPermi('community:repair:remove')")
    @Log(title = "报修信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repairIds}")
    public AjaxResult remove(@PathVariable Long[] repairIds)
    {
        return toAjax(repairService.deleteRepairByRepairIds(repairIds));
    }
}
